package com.mdb.open.common.enums.trade.type;

import com.mdb.bc.api.enums.ApiEnum;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 附件类型
 * @author: zhengzonghui
 * @create: 2019-06-26 12:20
 **/
public enum AttachFileTypeEnum implements ApiEnum<String> {

    OVERSEA_CONTRACT("海外合同") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }
    },
    EXPORTED_CONTRACT("出口合同") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }
    },
    PURCHASE_CONTRACT("采购合同") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }

        @Override
        public boolean isAllowNull() {
            return true;
        }
    },
    SALES_CONFIRMATION("销售确认书") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }

        @Override
        public boolean isAllowNull() {
            return true;
        }
    },
    CUSTOMS_DECLARATION("报关单") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }
    },
    EXPORTED_INVOICE("出口发票") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }
    },
    CONTAINER_LOAD_PLAN("装箱单") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }
    },
//    BUSINESS_CONFIRMATION("业务确认书") {
//        @Override
//        public FileGroupTypeEnum getGroup() {
//            return FileGroupTypeEnum.APPLY_ORDER;
//        }
//    },
    PARTICULAR_PAPER("验货/装柜单") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }

        @Override
        public boolean isAllowNull() {
        return true;
    }
    },
    TRANSIT("海关放行通知书") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }
    },
    BILL_LADING("提单") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }
    },
    VAT_INVOICE("增值税发票") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }

        @Override
        public boolean isAllowNull() {
            return true;
        }
    },
    DEPOSIT_EXCHANGE_MEMO("定金水单") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }

        @Override
        public boolean isAllowNull() {
            return true;
        }
    },
    EXPORTED_VERIFICATION_SLIP("出口核销单") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }

        @Override
        public boolean isAllowNull() {
            return true;
        }
    },
    OTHERS("其他证明文件") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.APPLY_ORDER;
        }

        @Override
        public boolean isAllowNull() {
            return true;
        }
    },
    TF_LOAN_CONTRACT("借据合同") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.LOAN_CONTRACT;
        }
    },
    CLAIM_SUPPLEMENTARY_EXPLANATION("认领补充说明") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.CLAIM_ORDER;
        }
    },
    OUTWARD_VERIFICATION_SLIP("汇出出口核销单") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.OUTWARD_ORDER;
        }
    },
    OUTWARD_PAYMENT_CERTIFICATE("汇出打款水单") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.OUTWARD_ORDER;
        }
    },
    LOAN_VERIFICATION_SLIP("贷款放款出口核销单") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.LOAN_ORDER;
        }
    },
    LOAN_PAYMENT_CERTIFICATE("贷款放款打款水单") {
        @Override
        public FileGroupTypeEnum getGroup() {
            return FileGroupTypeEnum.LOAN_ORDER;
        }
    },
    ;



    AttachFileTypeEnum(String text) {
        this.text = text;
    }


    //枚举描述
    private String text;
    /**
     * 分组函数
     *
     * @return
     */
    public abstract FileGroupTypeEnum getGroup();

    /**
     * 是否不允许为空
     *
     * @return
     */
    public boolean isAllowNull() {
        return false;
    }


    @Override
    public String getValue() {
        return this.name();
    }

    @Override
    public String getText() {
        return this.text;
    }


    public static List<AttachFileTypeEnum> findByGroup(FileGroupTypeEnum group, boolean isAllowNull) {
        List<AttachFileTypeEnum> list = new ArrayList<>();
        for (AttachFileTypeEnum fileType : AttachFileTypeEnum.values()) {
            if (isAllowNull == fileType.isAllowNull() && fileType.getGroup().equals(group)) {
                list.add(fileType);
            }
        }
        return list;
    }

    public static List<AttachFileTypeEnum> findByGroup(FileGroupTypeEnum group) {
        List<AttachFileTypeEnum> list = new ArrayList<>();
        for (AttachFileTypeEnum fileType : AttachFileTypeEnum.values()) {
            if (fileType.getGroup().equals(group)) {
                list.add(fileType);
            }
        }
        return list;
    }
//
//    /**
//     * 附件校验
//     *
//     * @param fileInfoDtos
//     * @param group
//     */
//    public static void validate(List<FileInfoDto> fileInfoDtos, FileGroup group) {
//        //按照文件类型分组
//        Map<String, List<FileInfoDto>> fileInfoDtoListMap = fileInfoDtos.stream().collect(Collectors.groupingBy(FileInfoDto::getFileTypeValue));
//
//        //获取分组必传附件列表
//        List<AttachFileTypeEnum> byGroup = findByGroup(group, true);
//        for (AttachFileTypeEnum fileType : byGroup) {
//            String value = fileType.getValue();
//            if (fileType.isAllowNull() && !fileInfoDtoListMap.containsKey(value)) {
//                throw new ValidationException("缺少附件[{}]", fileType.getText());
//            } else {
//
//            }
//        }
//    }
}